<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + 	request.getServerPort() + request.getContextPath() + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<base href="<%=basePath%>">
<meta charset="UTF-8">

<link href="jquery/bootstrap_3.3.0/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="jquery/jquery-1.11.1-min.js"></script>
<script type="text/javascript" src="jquery/bootstrap_3.3.0/js/bootstrap.min.js"></script>
    <!--日历控件-->
    <script type="text/javascript" src="jquery/bootstrap-datetimepicker-master/js/bootstrap-datetimepicker.js"></script>
    <script type="text/javascript" src="jquery/bootstrap-datetimepicker-master/locale/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript">

	//默认情况下取消和保存按钮是隐藏的
	var cancelAndSaveBtnDefault = true;
	
	$(function(){
		//alert("detail页面加载完毕")
		$("#remark").focus(function(){
			if(cancelAndSaveBtnDefault){
				//设置remarkDiv的高度为130px
				$("#remarkDiv").css("height","130px");
				//显示
				$("#cancelAndSaveBtn").show("2000");
				cancelAndSaveBtnDefault = false;
			}
		});
		
		$("#cancelBtn").click(function(){
			//显示
			$("#cancelAndSaveBtn").hide();
			//设置remarkDiv的高度为130px
			$("#remarkDiv").css("height","90px");
			cancelAndSaveBtnDefault = true;
		});
		
		$(".remarkDiv").mouseover(function(){
			$(this).children("div").children("div").show();
		});
		
		$(".remarkDiv").mouseout(function(){
			$(this).children("div").children("div").hide();
		});
		
		$(".myHref").mouseover(function(){
			$(this).children("span").css("color","red");
		});
		
		$(".myHref").mouseout(function(){
			$(this).children("span").css("color","#E6E6E6");
		});

		//页面加载完毕，展现该市场活动关联的备注信息
		showRemarkList()
        $("#remarkBody").on("mouseover",".remarkDiv",function(){
            $(this).children("div").children("div").show();
        })
        $("#remarkBody").on("mouseout",".remarkDiv",function(){
            $(this).children("div").children("div").hide();
        })


//为编辑按钮绑定事件，用于打开编辑市场活动的模态窗口
        $("#editActivityBtn").click(function ()     {
            alert("打开")
            $(".time").datetimepicker({
                minView: "month",
                language:  'zh-CN',
                format: 'yyyy-mm-dd',
                autoclose: true,
                todayBtn: true,
                pickerPosition: "bottom-left"
            });
            var id="${sessionScope.activity.id}"
                alert("市场活动的id"+id)
            $("#editActivityInDetail-ID").val(id)
            $.ajax({
                url:"/crm/activity/editActivityInDetail.do",
                type:"get",
                dataType:"json",
                data:{
                    "id":id
                },
                success:function (resp) {
             /*
             resp
                {"userlist":{用户列表},"activity":{市场活动}}
              */

                var html="<option></option>";
                $.each(resp.userlist,function (i,n) {
                    html+="<option value='"+n.id+"'>"+n.name+"</option>"
                })

                    $("#edit-marketActivityOwner").html(html)//铺垫所有者下拉列表

                    //处理单条activity
                    $("#edit-marketActivityName").val(resp.activity.name);
                    $("#edit-startTime").val(resp.activity.startDate);
                    $("#edit-endTime").val(resp.activity.endDate);
                    $("#edit-cost").val(resp.activity.cost);
                    $("#edit-describe").val(resp.activity.description);


                    $("#editActivityModal").modal("show");
                }
            })



        })
//为更新按钮绑定事件，执行【市场活动】的修改操作
        $("#updateActivityInDetailBtn").click(function () {
            //alert("事件绑定成功")
            var id=$("#editActivityInDetail-ID").val()
            //alert("id是"+id)
            alert($.trim($("#edit-marketActivityOwner").val()))
            $.ajax({
                url:"/crm/activity/updateActivityInDetail.do",
                type:"post",
                dataType:"json",
                data:{
                    "id":id,
                    "owner":$.trim($("#edit-marketActivityOwner").val()),
                    "name":$.trim($("#edit-marketActivityName").val()),
                    "startDate":$.trim($("#edit-startTime").val()),
                    "endDate":$.trim($("#edit-endTime").val()),
                    "cost":$.trim($("#edit-cost").val()),
                    "description":$.trim($("#edit-describe").val())
                },
                success:function (resp) {
                    if(resp){
                        alert("修改市场活动成功")
                        $("#top-activity").html("市场活动-"+$.trim($("#edit-marketActivityName").val())+" <small>"+$.trim($("#edit-startTime").val())+" ~ "+$.trim($("#edit-endTime").val())+"</small>")
                        $("#name").html($.trim($("#edit-marketActivityName").val()))
                        $("#startTime").html($.trim($("#edit-startTime").val()))
                        $("#endTime").html($.trim($("#edit-endTime").val()))
                        $("#cost").html($.trim($("#edit-cost").val()))
                        $("#describe").html($.trim($("#edit-describe").val()))
                        //$("#owner").html($.trim($("#edit-marketActivityOwner").html()))



                        $("#editActivityModal").modal("hide")

                    }else {
                        alert("修改市场活动失败")
                    }

                }
            })

        })

//为保存按钮绑定事件，执行备注的添加操作
        $("#saveRemarkBtn").click(function () {
            $.ajax({
                url:"/crm/activity/addRemark.do",
                type:"post",
                data:{
                    "noteContent":$.trim($("#remark").val()),
                    "activityId":"${activity.id}"
                },
                dataType:"json",
                success:function (resp) {
                    /*
                        resp:
                              {"success":true/false,"ar":{备注对象}}  ar就是activityRemark
                     */

                    if(resp.success){
                        alert("添加备注成功")
                        var html="";
                        html+='	<div id="'+resp.ar.id+'" class="remarkDiv" style="height: 60px;">';
                        html+='	<img title="zhangsan" src="image/user-thumbnail.png" style="width: 30px; height:30px;">';
                        html+='	<div style="position: relative; top: -40px; left: 40px;" >';
                        html+='	<h5>'+resp.ar.noteContent+'</h5>';
                        html+='<font color="gray">市场活动</font> <font color="gray">-</font> <b>${activity.name}</b> <small style="color: gray;"> '+(resp.ar.createTime)+' 由'+(resp.ar.createBy)+'</small>';
                        html+='<div style="position: relative; left: 500px; top: -30px; height: 30px; width: 100px; display: none;">';
                        html+='<a class="myHref" href="javascript:void(0);" onclick="editRemark(\''+resp.ar.id+'\')" ><span class="glyphicon glyphicon-edit" style="font-size: 20px; color: #FF0000;"></span></a>';
                        html+='&nbsp;&nbsp;&nbsp;&nbsp;';
                        html+='<a class="myHref" href="javascript:void(0);" onclick="deleteRemark(\''+resp.ar.id+'\')"><span class="glyphicon glyphicon-remove" style="font-size: 20px; color: #FF0000;"></span></a>';
                        html+='</div>';
                        html+='</div>';
                        html+='</div>';

                        $("#remarkDiv").before(html)
                        $("#remark").val("")
                    }else {
                        alert("添加备注失败")
                    }
                }
            })

        })

//为更新按钮绑定事件，执行备注的修改操作
        $("#updateRemarkBtn").click(function ()     {
            var noteContent=$.trim($("#noteContent").val())
            var id=$("#updateRemark-id").val()
            //alert("隐藏域中的id"+id)
            $.ajax({
                url:"/crm/activity/updateRemark.do",
                type:"post",
                dataType:"json",
                data:{
                    "noteContent":noteContent,
                    "id":id
                },
                success:function (resp) {

                    if(resp.success){
                        alert("修改备注成功")
                        $("#e"+id).html(noteContent)
                        $("#s"+id).html(resp.activityRemark.editTime+' 由'+resp.activityRemark.editBy)
                        $("#editRemarkModal").modal("hide")
                    }else {
                        alert("修改备注失败")
                    }
                }
            })
        })

    });
//页面加载完毕分隔线===================================================================================

//显示市场活动信息的成员方法
    function showActivityDetail() {
        alert("showActivityDetail方法执行")
        var owner="${activity.owner}"
        var name="${activity.name}"
       // $("#top-activity").html("市场活动-"+"'${activity.name}''"+" <small>"+"'${activity.startDate}''"+" ~ "+"'${activity.endDate}'"+"</small>")

        $("#owner").html(owner)
        $("#name").html(name)

    }


//显示备注信息列表的成员方法
	function showRemarkList() {
		$.ajax({
			url:"/crm/activity/viewRemark.do",
			type:"get",
			dataType:"json",
			data:{
				"activityId":"${activity.id}"//注意！！！在js中写EL表达式需要套用字符串
			},
			success:function (resp) {
				//alert("showRemarkList回调函数执行")
				/*
				resp:[{备注1},{备注2},{备注3}]

				 */
				var html="";
				$.each(resp,function (i,n) {

					html+='	<div id="'+n.id+'" class="remarkDiv" style="height: 60px;">';
					html+='	<img title="zhangsan" src="image/user-thumbnail.png" style="width: 30px; height:30px;">';
					html+='	<div style="position: relative; top: -40px; left: 40px;" >';
					html+='	<h5 id="e'+n.id+'">'+n.noteContent+'</h5>';
					html+='<font color="gray">市场活动</font> <font color="gray">-</font> <b>${activity.name}</b> <small style="color: gray;" id="s'+n.id+'"> '+(n.editFlag==0?n.createTime:n.editTime)+' 由'+(n.editFlag==0?n.createBy:n.editBy)+'</small>';
					html+='<div style="position: relative; left: 500px; top: -30px; height: 30px; width: 100px; display: none;">';
					html+='<a class="myHref" href="javascript:void(0);" onclick="editRemark(\''+n.id+'\')"><span class="glyphicon glyphicon-edit" style="font-size: 20px; color: #FF0000;"></span></a>';
					html+='&nbsp;&nbsp;&nbsp;&nbsp;';
					html+='<a class="myHref" href="javascript:void(0);" onclick="deleteRemark(\''+n.id+'\')"><span class="glyphicon glyphicon-remove" style="font-size: 20px; color: #FF0000;"></span></a>';
					html+='</div>';
					html+='</div>';
					html+='</div>';

				})

				$("#remarkDiv").before(html)
			}

		})
	}
//为删除备注按钮绑定事件，执行删除备注操作
	function deleteRemark(id) {
	    //遍历中动态生成的元素，动态触发事件
        //alert(id)
        if (confirm("确定要删除该备注吗？")){
            $.ajax({
                url:"/crm/activity/deleteRemarkById.do",
                type:"post",
                data: {
                    "id":id
                },
                dataType: "json",
                success:function (resp) {
                    if(resp){
                        //showRemarkList()  这种方式不行，因为们动态拼接用的before
                        alert("删除备注成功")
                        $("#"+id).remove();
                    }else {
                        alert("删除备注失败")
                    }
                }
            })
        }

    }


//为编辑备注按钮绑定事件,打开修改备注的模态窗口
    function editRemark(id) {

        $.ajax({
            url:"/crm/activity/editRemark.do",
            type:"post",
            data:{
                "id":id
            },
            dataType:"json",
            success:function (resp) {
                /*
                resp
                    {"success":true/false,"activityRemark":{备注对象}}

                 */
                if(resp.success){
                    var noteContent=resp.activityRemark.noteContent
                    $("#noteContent").val(noteContent)
                    $("#updateRemark-id").val(id)
                    $("#editRemarkModal").modal("show")
                }else {
                    alert("修改备注信息失败")
                }
            }
        })
    }


</script>

</head>
<body>
	
	<!-- 修改市场活动备注的模态窗口 -->
	<div class="modal fade" id="editRemarkModal" role="dialog">
		<%-- 备注的id --%>
		<input type="hidden" id="remarkId">
        <div class="modal-dialog" role="document" style="width: 40%;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">×</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">修改备注</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">
                        <input type="hidden" id="updateRemark-id">
                        <div class="form-group">
                            <label for="edit-describe" class="col-sm-2 control-label">内容</label>
                            <div class="col-sm-10" style="width: 81%;">
                                <textarea class="form-control" rows="3" id="noteContent">0.0</textarea>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="updateRemarkBtn">更新</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 修改市场活动的模态窗口 -->
    <div class="modal fade" id="editActivityModal" role="dialog">
        <div class="modal-dialog" role="document" style="width: 85%;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        <span aria-hidden="true">×</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">修改市场活动</h4>
                </div>
                <div class="modal-body">

                    <form class="form-horizontal" role="form">
                    <input type="hidden" id="editActivityInDetail-ID">
                        <div class="form-group">
                            <label for="edit-marketActivityOwner" class="col-sm-2 control-label">所有者<span style="font-size: 15px; color: red;">*</span></label>
                            <div class="col-sm-10" style="width: 300px;">
                                <select class="form-control" id="edit-marketActivityOwner">

                                </select>
                            </div>
                            <label for="edit-marketActivityName" class="col-sm-2 control-label">名称<span style="font-size: 15px; color: red;">*</span></label>
                            <div class="col-sm-10" style="width: 300px;">
                                <input type="text" class="form-control" id="edit-marketActivityName" >
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="edit-startTime" class="col-sm-2 control-label ">开始日期</label>
                            <div class="col-sm-10" style="width: 300px;">
                                <input type="text" class="form-control time" id="edit-startTime"  readonly>
                            </div>
                            <label for="edit-endTime" class="col-sm-2 control-label ">结束日期</label>
                            <div class="col-sm-10" style="width: 300px;">
                                <input type="text" class="form-control time" id="edit-endTime"  readonly>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="edit-cost" class="col-sm-2 control-label">成本</label>
                            <div class="col-sm-10" style="width: 300px;">
                                <input type="text" class="form-control" id="edit-cost" >
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="edit-describe" class="col-sm-2 control-label">描述</label>
                            <div class="col-sm-10" style="width: 81%;">
                                <textarea class="form-control" rows="3" id="edit-describe"></textarea>
                            </div>
                        </div>

                    </form>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="updateActivityInDetailBtn">更新</button>
                </div>
            </div>
        </div>
    </div>

	<!-- 返回按钮 -->
	<div style="position: relative; top: 35px; left: 10px;">
		<a href="javascript:void(0);" onclick="window.history.back();"><span class="glyphicon glyphicon-arrow-left" style="font-size: 20px; color: #DDDDDD"></span></a>
	</div>
	
	<!-- 大标题 -->
	<div style="position: relative; left: 40px; top: -30px;">
		<div class="page-header">
			<h3 id="top-activity">市场活动-${activity.name} <small>${activity.startDate} ~ ${activity.endDate}</small></h3>
		</div>
		<div style="position: relative; height: 50px; width: 250px;  top: -72px; left: 700px;">
			<button type="button" class="btn btn-default" data-toggle="modal" id="editActivityBtn"><span class="glyphicon glyphicon-edit"></span> 编辑asa</button>
			<button type="button" class="btn btn-danger"><span class="glyphicon glyphicon-minus"></span> 删除</button>
		</div>
	</div>
	
	<!-- 详细信息 -->
	<div style="position: relative; top: -70px;">
		<div style="position: relative; left: 40px; height: 30px;">
			<div style="width: 300px; color: gray;">所有者</div>
			<div style="width: 300px;position: relative; left: 200px; top: -20px;"><b id="owner">${activity.owner}</b></div>
			<div style="width: 300px;position: relative; left: 450px; top: -40px; color: gray;">名称</div>
			<div style="width: 300px;position: relative; left: 650px; top: -60px;"><b id="name">${activity.name}</b></div>
			<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px;"></div>
			<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px; left: 450px;"></div>
		</div>

		<div style="position: relative; left: 40px; height: 30px; top: 10px;">
			<div style="width: 300px; color: gray;">开始日期</div>
			<div style="width: 300px;position: relative; left: 200px; top: -20px;"><b id="startTime">${activity.startDate}</b></div>
			<div style="width: 300px;position: relative; left: 450px; top: -40px; color: gray;">结束日期</div>
			<div style="width: 300px;position: relative; left: 650px; top: -60px;"><b id="endTime">${activity.endDate}</b></div>
			<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px;"></div>
			<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -60px; left: 450px;"></div>
		</div>
		<div style="position: relative; left: 40px; height: 30px; top: 20px;">
			<div style="width: 300px; color: gray;">成本</div>
			<div style="width: 300px;position: relative; left: 200px; top: -20px;"><b id="cost">${activity.cost}</b></div>
			<div style="height: 1px; width: 400px; background: #D5D5D5; position: relative; top: -20px;"></div>
		</div>
		<div style="position: relative; left: 40px; height: 30px; top: 30px;">
			<div style="width: 300px; color: gray;">创建者</div>
			<div style="width: 500px;position: relative; left: 200px; top: -20px;"><b>${activity.createBy}&nbsp;&nbsp;</b><small style="font-size: 10px; color: gray;">${activity.createTime}</small></div>
			<div style="height: 1px; width: 550px; background: #D5D5D5; position: relative; top: -20px;"></div>
		</div>
		<div style="position: relative; left: 40px; height: 30px; top: 40px;">
			<div style="width: 300px; color: gray;">修改者</div>
			<div style="width: 500px;position: relative; left: 200px; top: -20px;"><b id="editBy">${activity.editBy}&nbsp;&nbsp;</b><small style="font-size: 10px; color: gray;">${activity.editTime}</small></div>
			<div style="height: 1px; width: 550px; background: #D5D5D5; position: relative; top: -20px;"></div>
		</div>
		<div style="position: relative; left: 40px; height: 30px; top: 50px;">
			<div style="width: 300px; color: gray;">描述</div>
			<div style="width: 630px;position: relative; left: 200px; top: -20px;">
				<b id="describe">
					${activity.description}
				</b>
			</div>
			<div style="height: 1px; width: 850px; background: #D5D5D5; position: relative; top: -20px;"></div>
		</div>
	</div>
	
	<!-- 备注 -->
	<div id="remarkBody" style="position: relative; top: 30px; left: 40px;">
		<div class="page-header">
			<h4>备注sss</h4>
		</div>
		
		<!-- 备注1 -->
		<%--<div class="remarkDiv" style="height: 60px;">
			<img title="zhangsan" src="image/user-thumbnail.png" style="width: 30px; height:30px;">
			<div style="position: relative; top: -40px; left: 40px;" >
				<h5>哎呦！</h5>
				<font color="gray">市场活动</font> <font color="gray">-</font> <b>发传单</b> <small style="color: gray;"> 2017-01-22 10:10:10 由zhangsan</small>
				<div style="position: relative; left: 500px; top: -30px; height: 30px; width: 100px; display: none;">
					<a class="myHref" href="javascript:void(0);"><span class="glyphicon glyphicon-edit" style="font-size: 20px; color: #E6E6E6;"></span></a>
					&nbsp;&nbsp;&nbsp;&nbsp;
					<a class="myHref" href="javascript:void(0);"><span class="glyphicon glyphicon-remove" style="font-size: 20px; color: #E6E6E6;"></span></a>
				</div>
			</div>
		</div>--%>
		
		<!-- 备注2 -->
		<%--<div class="remarkDiv" style="height: 60px;">
			<img title="zhangsan" src="image/user-thumbnail.png" style="width: 30px; height:30px;">
			<div style="position: relative; top: -40px; left: 40px;" >
				<h5>呵呵！</h5>
				<font color="gray">市场活动</font> <font color="gray">-</font> <b>发传单</b> <small style="color: gray;"> 2017-01-22 10:20:10 由zhangsan</small>
				<div style="position: relative; left: 500px; top: -30px; height: 30px; width: 100px; display: none;">
					<a class="myHref" href="javascript:void(0);"><span class="glyphicon glyphicon-edit" style="font-size: 20px; color: #E6E6E6;"></span></a>
					&nbsp;&nbsp;&nbsp;&nbsp;
					<a class="myHref" href="javascript:void(0);"><span class="glyphicon glyphicon-remove" style="font-size: 20px; color: #E6E6E6;"></span></a>
				</div>
			</div>
		</div>--%>
		
		<div id="remarkDiv" style="background-color: #E6E6E6; width: 870px; height: 90px;">
			<form role="form" style="position: relative;top: 10px; left: 10px;">
				<textarea id="remark" class="form-control" style="width: 850px; resize : none;" rows="2"  placeholder="添加备注..."></textarea>
				<p id="cancelAndSaveBtn" style="position: relative;left: 737px; top: 10px; display: none;">
					<button id="cancelBtn" type="button" class="btn btn-default">取消</button>
					<button type="button" class="btn btn-primary" id="saveRemarkBtn">保存</button>
				</p>
			</form>
		</div>
	</div>
	<div style="height: 200px;"></div>
</body>
</html>